s="42"
def calc(numsStack,signalStack):
    if len(numsStack)==0 or len(numsStack)<2:
        return None
    if len(signalStack)==0:
        return None
    b=numsStack.pop()
    a=numsStack.pop()
    ops=signalStack.pop()
    ans=0
    if ops=="+":
        ans=int(a+b)
    elif ops=="-":
        ans=int(a-b)
    elif ops=="*":
        ans=int(a*b)
    elif ops=="/":
        ans=int(a/b)
    numsStack.append(ans)
def calculate(s: str) -> int:
    map = {'-': 1, '+': 1, '*': 2, '/': 2, '%': 2, '^': 3}
    #写一个用来存数字的栈
    numsStack=[]
    #为了防止第一个数是负数，先往numsStack里面放一个0
    numsStack.append(0)
    #创建另一个栈，存放操作符
    signalStack=[]
    i=0
    while i<len(s):
        e=s[i]
        #如果是数字
        if e.isnumeric():
            u=0
            j=i
            while j<len(s) and s[j].isnumeric():
                u=u*10+int(s[j])
                j+=1
            numsStack.append(u)
            i=j-1
        else:
            while len(signalStack)>0:
                prev=signalStack[len(signalStack)-1]
                if map[prev]>=map[e]:
                    calc(numsStack,signalStack)
                else:
                    break
            signalStack.append(e)
        i+=1
    while len(signalStack)>0:
        calc(numsStack,signalStack)
    print(numsStack)
    return numsStack.pop()

print(calculate(s))